
import {ø} from "../util/objects.js";
import {sharedStore} from "../framework/sharedStore.js";


const handlers = {
    "air":          () => ({overlay_type: "wind",                    animation_type: "wind"}),
    "ocean":        () => ({overlay_type: "significant_wave_height", animation_type: "primary_waves"}),
    "chem":         () => ({overlay_type: "co2sc",                   animation_type: "wind"}),
    "particulates": () => ({overlay_type: "pm2.5",                   animation_type: "wind"}),
    "space":        () => ({overlay_type: "aurora",                  animation_enabled: false}),
};

/**
 * handler for Mode change events
 *
 * @param {string} mode
 * @param {*} meta
 */
export function switchMode(mode, meta) {
    const currentMode = sharedStore.get("mode");
    if (mode === currentMode) {
        return;
    }

    const attr = ø({mode}, handlers[mode]?.() ?? {});
    if (currentMode === "space") {
        // switching away from "space" mode re-enables the animation that was turned off when entering "space" mode
        attr.animation_enabled = true;
    }
    sharedStore.save(attr, meta);
}
